//Lake Counting S:https://www.luogu.com.cn/problem/P1596


#include <iostream>
#include <unordered_map>
#include <cstring>

using namespace std;

const int N = 105;

char p[N][N];
int fa[N * N];
bool st[N][N];
int n, m;

int dx[] = { -1,-1,-1,0,0,1,1,1 };
int dy[] = { 0,-1,1,-1,1,-1,0,1 };

int find(int x)
{
	return fa[x] == x ? x : fa[x] = find(fa[x]);
}

int main()
{
	cin >> n >> m;
	memset(fa, -1, sizeof fa);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> p[i][j];
			int s = i * m + j;
			if (p[i][j] == 'W')
				fa[s] = s;
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			st[i][j] = true;
			if (p[i][j] == '.')continue;
			int r = i * m + j;
			int x = find(r);
			for (int k = 0; k < 8; k++)
			{
				int a = i + dx[k];
				int b = j + dy[k];
				if (a < 0 || b < 0 || a >= n || b >= m || st[a][b] == true) continue;
				if (p[a][b] == '.')
				{
					st[a][b] = true;
					continue;
				}
				int s = a * m + b;
				int y = find(s);
				fa[y] = x;
			}
		}
	}

	unordered_map<int, bool> ma;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (p[i][j] == '.')continue;
			int s = i * m + j;
			int x = find(s);
			ma[x];
		}
	}
	cout << ma.size() << endl;

	return 0;
}
